#!/usr/bin/python

"""
   Implementation of this script has been moved to AnalizaLogow application
"""

import sys, string

"""
    analizator.py input_file output_file extension
"""

"""
otto.ucns.uga.edu - - [01/Jul/1995:10:20:41 -0400] "GET /shuttle/missions/61-b/mission-61-b.html HTTP/1.0" 200 6503
131.182.28.171 - - [01/Jul/1995:10:20:33 -0400] "GET /history/gemini/gemini-v/gemini-v-patch-small.gif HTTP/1.0" 200 19150
slip183-11.kw.jp.ibm.net - - [01/Jul/1995:10:20:35 -0400] "GET /history/mercury/mercury.html HTTP/1.0" 200 1871
www-a2.proxy.aol.com - - [01/Jul/1995:10:20:37 -0400] "GET / HTTP/1.0" 200 7074
ix-akr-oh2-10.ix.netcom.com - - [01/Jul/1995:10:20:41 -0400] "GET /software/winvn/winvn.gif HTTP/1.0" 200 25218

"""

def parse(input_file, output_file):
    print('Start working...')
    logfile = open(input_file)
    newfile = open(output_file, 'w')

    while 1:
        line = logfile.readline()
        if not line:
            break

        b = line.find('"') + 1
        e = line.find('"', b)

        if line[b:e].find(".html") != -1 or (line[b:e])[-10:-9] == "/":
            if (line[b:e])[0:3] == "GET":
                # This line is correct
                #print(line)
                newfile.write(line)

    print("It has been done.")
    newfile.close()
    logfile.close()


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print('Error inccorect usage\n./apanlizator.py input_filename output_filename')
    else:
        #parse('small.txt', 'clean.txt')
        parse(sys.argv[1], sys.argv[2])

